// 云函数入口文件
/*在点击加入购物车且购物车无此商品时调用 */
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  var id = event.id
  var num = 1
  var uid = event.uid
  var data = {id, num}
  return await db.collection("cart").where({
    uid: uid,
  }).update({
    data: {
      pids: _.push(data)
    }
  })
}